package com.e.progressanimator;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class ProgressView extends View {
    private Paint mPaint;
    private int progress = 88;

    public void setProgress(int progress) {
        this.progress = progress;
        invalidate();
    }

    public ProgressView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    private void initPaint() {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setStrokeWidth(20);
        mPaint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        mPaint.setColor(Color.RED);
        canvas.drawCircle(350, 300, 200, mPaint);

        //绘制文字
        mPaint.setColor(Color.BLUE);
        mPaint.setStrokeWidth(2);
        mPaint.setTextSize(80);
        canvas.drawText(progress + "%", 280, 300, mPaint);

        //绘制圆弧
        mPaint.setStrokeWidth(18);
        canvas.drawArc(150, 100, 550, 500, 270, 360 * progress / 100, false, mPaint);
    }
}
